<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="85%"
			   destroy-on-close @closed="$emit('closed')" align-center>
		<el-container>
			<el-header>
				<div class="left-panel">
					<el-button type="primary" @click="back">确定</el-button>
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-date-picker v-model="search.create_time" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期"
										end-placeholder="结束日期"/>
						<el-input v-model="search.code" placeholder="采购单号" clearable @keyup.enter="upsearch"></el-input>
						<el-select v-model="search.apply_id" placeholder="请选择供应商" filterable clearable>
							<el-option v-for="item in applyList" :key="item.apply_id" :label="item.apply_name" :value="item.apply_id"></el-option>
						</el-select>
						<el-select v-model="search.purchase_staff" filterable clearable placeholder="请选择采购人">
							<el-option v-for="item in adminList" :key="item.id" :label="item.name" :value="item.id"/>
						</el-select>
						<el-select v-model="search.is_ticket" placeholder="是否开票" filterable clearable>
							<el-option label="否" :value="1"></el-option>
							<el-option label="是" :value="2"></el-option>
						</el-select>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" row-key="id" :apiObj="apiObj" @row-click="selectionChange" stripe remoteSort remoteFilter border height="650">
					<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
					<el-table-column type="index" width="50" align="center"></el-table-column>
					<el-table-column label="采购入库单号" prop="purchase_code" align="center"></el-table-column>
					<el-table-column label="开单日期" prop="open_date" align="center"></el-table-column>
					<el-table-column label="采购单号" prop="purchase.code" align="center"></el-table-column>
					<el-table-column label="入库日期" prop="entry_date" align="center"></el-table-column>
					<el-table-column label="备注" prop="remark" align="center"></el-table-column>
					<el-table-column label="收货人" prop="collect_staff" align="center"></el-table-column>
					<el-table-column label="创建人" prop="admin.name" align="center"></el-table-column>
					<el-table-column label="创建时间" prop="create_time" align="center"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择采购入库单',
				edit: '编辑产品',
				show: '查看'
			},
			visible: false,
			isSaveing: false,
			apiObj: this.$API.procure.inorder.list,
			selection: [],
			search: {
				code: null,
				apply_id: null,
				purchase_staff: null,
				is_ticket: null,
				is_tax: null,
				goods_name: null,
				create_time: null
			},
			applyList: [],
			adminList: [],
		}
	},
	mounted() {
		this.getApply();
		this.getAdmin();
	},
	methods: {
		// 显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		// 选择事件
		selectionChange(selection) {
			// this.selection = selection;
			this.$emit('success', selection)
			this.visible = false;
		},
		// 选中返回
		back() {
			this.$emit('success', this.selection)
			this.visible = false;
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		refresh() {
			for (const key in this.search) {
				this.search[key] = null;
			}
			this.$refs.table.upData(this.search)
		},
		// 供应商
		async getApply() {
			var res = await this.$API.apply.apply.all.get();
			this.applyList = res.data;
		},
		// 获取采购人
		async getAdmin() {
			var res = await this.$API.system.admin.all.get();
			this.adminList = res.data;
		},
	}
}
</script>

<style></style>
